package com.mingtu.guards.activity;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mingtu.common.utils.ActivityUtil;
import com.mingtu.common.utils.StatusBarUtil;
import com.mingtu.guards.R;
import com.mingtu.guards.adapter.PhotoAdapter;
import com.mingtu.guards.base.MyBaseActivity;
import com.mingtu.guards.bean.InfraredRecordImgBean;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnPageChangeListener;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class PhotoViewActivity extends MyBaseActivity {

    @BindView(R.id.banner)
    Banner banner;
    @BindView(R.id.status_bar_view)
    View statusBarView;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    private List<InfraredRecordImgBean.DataBean.ListBean> listBeans;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_photo_view;
    }

    @Override
    protected void initView() {
        hideHeadView();
        StatusBarUtil.addStatusBarHeight(statusBarView);
    }

    @Override
    protected void initData() {
        //前面已经做了 判空逻辑
        listBeans = (List<InfraredRecordImgBean.DataBean.ListBean>) getIntent().getSerializableExtra("list");
        int position = getIntent().getIntExtra("positon", 0);

        setCurrentTitle((position + 1));

        PhotoAdapter photoAdapter = new PhotoAdapter(context, listBeans);
        banner.isAutoLoop(false); //是否允许自动轮播
        banner.setAdapter(photoAdapter, true);
        banner.addOnPageChangeListener(new OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                setCurrentTitle((position + 1));
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void getData() {

    }


    @OnClick({R.id.iv_back})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                ActivityUtil.removeActivity(this);
                break;
        }
    }

    private void setCurrentTitle(int position) {

        if(listBeans != null){
            if(listBeans.size() > 0){
                tvTitle.setText((position + 1) + "/" + listBeans.size());
            }
        }

    }
}